package com.future.mayi.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.future.baselib.utils.LogUtils;
import com.future.mayi.R;
import com.future.mayi.constant.AppCst;
import com.future.mayi.utils.SharedPreferencesUtils;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wechat_pay_result);
        api = WXAPIFactory.createWXAPI(this, AppCst.Wechat_APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp baseResp) {
        LogUtils.d(TAG, "onPayFinish, errCode = " + baseResp.errCode + ":" + baseResp.errStr);
        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
                SharedPreferencesUtils.set(this, SharedPreferencesUtils.SpEnum.WxPayResp, baseResp.errCode);
            }
        }
        finish();
    }
}